﻿Imports Castle.ActiveRecord
Imports NHibernate
Imports NHibernate.Criterion

Namespace Model
    <Serializable(), ActiveRecord("tr_situac_trib", DynamicUpdate:=True)> _
    Public Class Tr_Situac_Trib
        Inherits ActiveRecordBase(Of Model.Tr_Situac_Trib)

        Public Enum Tributo As Short
            ICMS = 1
            IPI = 2
            PIS = 3
            COFINS = 4
        End Enum

        Private _cd_tr_situac_trib As Integer
        Private _st_numero As String
        Private _st_tributo As String
        Private _st_nome As String

        Private _ProdutoSituacTribICMS As IList(Of Model.Produto)
        Private _produtoSituacTribIPI As IList(Of Model.Produto)
        Private _produtoSituacTribPIS As IList(Of Model.Produto)
        Private _produtoSituacTribCOFINS As IList(Of Model.Produto)

        Private _ItemSituacTribICMS As IList(Of Model.Nfitem) = New List(Of Model.Nfitem)
        Private _ItemSituacTribIPI As IList(Of Model.Nfitem) = New List(Of Model.Nfitem)
        Private _ItemSituacTribPIS As IList(Of Model.Nfitem) = New List(Of Model.Nfitem)
        Private _ItemSituacTribCOFINS As IList(Of Model.Nfitem) = New List(Of Model.Nfitem)

        <PrimaryKey(PrimaryKeyType.Sequence, SequenceName:="tr_situac_trib_cd_tr_situac_trib_seq")> _
        Public Property cd_tr_situac_trib() As Integer
            Get
                Return _cd_tr_situac_trib
            End Get
            Set(ByVal value As Integer)
                _cd_tr_situac_trib = value
            End Set
        End Property

        <[Property]("st_numero")> _
         Public Property st_numero() As String
            Get
                Return _st_numero
            End Get
            Set(ByVal value As String)
                _st_numero = value
            End Set
        End Property

        <[Property]("st_tributo")> _
           Public Property st_tributo() As String
            Get
                Return _st_tributo
            End Get
            Set(ByVal value As String)
                _st_tributo = value
            End Set
        End Property

        <[Property]("st_nome")> _
        Public Property st_nome() As String
            Get
                Return _st_nome
            End Get
            Set(ByVal value As String)
                _st_nome = value
            End Set
        End Property

        <HasMany(GetType(Model.Produto), Table:="produto", ColumnKey:="cd_tr_situac_trib_icms", Inverse:=True, Lazy:=True)> _
        Public Property ProdutoSituacTribICMS() As IList(Of Model.Produto)
            Get
                Return _ProdutoSituacTribICMS
            End Get
            Set(ByVal value As IList(Of Model.Produto))
                _ProdutoSituacTribICMS = value
            End Set
        End Property

        <HasMany(GetType(Model.Produto), Table:="produto", ColumnKey:="cd_tr_situac_trib_ipi", Inverse:=True, Lazy:=True)> _
        Public Property ProdutoSituacTribIPI() As IList(Of Model.Produto)
            Get
                Return _produtoSituacTribIPI
            End Get
            Set(ByVal value As IList(Of Model.Produto))
                _produtoSituacTribIPI = value
            End Set
        End Property

        <HasMany(GetType(Model.Produto), Table:="produto", ColumnKey:="cd_tr_situac_trib_pis", Inverse:=True, Lazy:=True)> _
        Public Property ProdutoSituacTribPIS() As IList(Of Model.Produto)
            Get
                Return _produtoSituacTribPIS
            End Get
            Set(ByVal value As IList(Of Model.Produto))
                _produtoSituacTribPIS = value
            End Set
        End Property

        <HasMany(GetType(Model.Produto), Table:="produto", ColumnKey:="cd_tr_situac_trib_cofins", Inverse:=True, Lazy:=True)> _
        Public Property ProdutoSituacTribCOFINS() As IList(Of Model.Produto)
            Get
                Return _produtoSituacTribCOFINS
            End Get
            Set(ByVal value As IList(Of Model.Produto))
                _produtoSituacTribCOFINS = value
            End Set
        End Property


        <HasMany(GetType(Model.Nfitem), Table:="nfitem", ColumnKey:="cd_tr_situac_trib_icms", Inverse:=True, Lazy:=True)> _
        Public Property ItemSituacTribICMS() As IList(Of Model.Nfitem)
            Get
                Return _ItemSituacTribICMS
            End Get
            Set(ByVal value As IList(Of Model.Nfitem))
                _ItemSituacTribICMS = value
            End Set
        End Property

        <HasMany(GetType(Model.Nfitem), Table:="nfitem", ColumnKey:="cd_tr_situac_trib_ipi", Inverse:=True, Lazy:=True)> _
        Public Property ItemSituacTribIPI() As IList(Of Model.Nfitem)
            Get
                Return _ItemSituacTribIPI
            End Get
            Set(ByVal value As IList(Of Model.Nfitem))
                _ItemSituacTribIPI = value
            End Set
        End Property

        <HasMany(GetType(Model.Nfitem), Table:="nfitem", ColumnKey:="cd_tr_situac_trib_pis", Inverse:=True, Lazy:=True)> _
        Public Property ItemSituacTribPIS() As IList(Of Model.Nfitem)
            Get
                Return _ItemSituacTribPIS
            End Get
            Set(ByVal value As IList(Of Model.Nfitem))
                _ItemSituacTribPIS = value
            End Set
        End Property

        <HasMany(GetType(Model.Nfitem), Table:="nfitem", ColumnKey:="cd_tr_situac_trib_cofins", Inverse:=True, Lazy:=True)> _
        Public Property ItemSituacTribCOFINS() As IList(Of Model.Nfitem)
            Get
                Return _ItemSituacTribCOFINS
            End Get
            Set(ByVal value As IList(Of Model.Nfitem))
                _ItemSituacTribCOFINS = value
            End Set
        End Property

        Public Function GetByTributo(ByVal Tributo As Model.Tr_Situac_Trib.Tributo) As IList(Of Model.Tr_Situac_Trib)

            Dim q As DetachedCriteria = DetachedCriteria.For(Of Model.Tr_Situac_Trib)("tr_situac_trib")

            Select Tributo
                Case Tr_Situac_Trib.Tributo.ICMS
                    q.Add(Restrictions.Eq("st_tributo", CType("ICMS", String)))
                Case Tr_Situac_Trib.Tributo.IPI
                    q.Add(Restrictions.Eq("st_tributo", CType("IPI", String)))
                Case Tr_Situac_Trib.Tributo.PIS
                    q.Add(Restrictions.Eq("st_tributo", CType("PIS", String)))
                Case Tr_Situac_Trib.Tributo.COFINS
                    q.Add(Restrictions.Eq("st_tributo", CType("COFINS", String)))
            End Select

            Return Model.Tr_Situac_Trib.FindAll(q)
        End Function

    End Class
End Namespace